<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" draggable :show-fullscreen="true" :width="500" destroy-on-close @closed="$emit('closed')">
        <el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="120px" label-position="left">
            <el-form-item label="售后单号" prop="aftersale_sn">
                <el-input v-model="form.aftersale_sn" clearable></el-input>
        	</el-form-item>
            <el-form-item label="用户" prop="user_id">
                <el-input-number v-model="form.user_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="类型" prop="type">
                <el-radio v-model="form.type" v-for="(item,index) in type_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>
            <el-form-item label="售后类型" prop="type_str">
                <el-input v-model="form.type_str" clearable></el-input>
        	</el-form-item>
            <el-form-item label="联系方式" prop="phone">
                <el-input v-model="form.phone" clearable></el-input>
        	</el-form-item>
            <el-form-item label="活动" prop="activity_id">
                <el-input-number v-model="form.activity_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="活动类型" prop="activity_type">
                <el-select v-model="form.activity_type" clearable placeholder="请选择活动类型">
            <el-option v-for="(item,index) in activity_type_option" :key="index" :label="item" :value="index"></el-option>
        </el-select>
        	</el-form-item>
            <el-form-item label="订单" prop="order_id">
                <el-input-number v-model="form.order_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="订单商品" prop="order_item_id">
                <el-input-number v-model="form.order_item_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="商品" prop="goods_id">
                <el-input-number v-model="form.goods_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="规格 id" prop="goods_sku_price_id">
                <el-input-number v-model="form.goods_sku_price_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="规格名" prop="goods_sku_text">
                <el-input v-model="form.goods_sku_text" clearable></el-input>
        	</el-form-item>
            <el-form-item label="商品名称" prop="goods_title">
                <el-input v-model="form.goods_title" clearable></el-input>
        	</el-form-item>
            <el-form-item label="商品图片" prop="goods_image">
                <sc-upload v-model="form.goods_image" icon="el-icon-picture-outline"></sc-upload>
        	</el-form-item>
            <el-form-item label="商品原价" prop="goods_original_price">
                <el-input-number v-model="form.goods_original_price"></el-input-number>
        	</el-form-item>
            <el-form-item label="优惠费用" prop="discount_fee">
                <el-input-number v-model="form.discount_fee"></el-input-number>
        	</el-form-item>
            <el-form-item label="商品价格" prop="goods_price">
                <el-input-number v-model="form.goods_price"></el-input-number>
        	</el-form-item>
            <el-form-item label="购买数量" prop="goods_num">
                <el-input-number v-model="form.goods_num"></el-input-number>
        	</el-form-item>
            <el-form-item label="发货状态" prop="dispatch_status">
                <el-switch v-model="form.dispatch_status" :active-value="1" :inactive-value="0"></el-switch>
        	</el-form-item>
            <el-form-item label="发货费用" prop="dispatch_fee">
                <el-input-number v-model="form.dispatch_fee"></el-input-number>
        	</el-form-item>
            <el-form-item label="售后状态" prop="aftersale_status">
                <el-switch v-model="form.aftersale_status" :active-value="1" :inactive-value="0"></el-switch>
        	</el-form-item>
            <el-form-item label="退款状态" prop="refund_status">
                <el-radio v-model="form.refund_status" v-for="(item,index) in refund_status_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>
            <el-form-item label="买家备注" prop="ps">
                <el-input v-model="form.ps" clearable></el-input>
        	</el-form-item>
            <el-form-item label="卖家备注" prop="memo">
                <el-input v-model="form.memo" clearable></el-input>
        	</el-form-item>
            <el-form-item label="买家图集" prop="images">
                <sc-upload-multiple v-model="form.images"></sc-upload-multiple>
        	</el-form-item>
            <el-form-item label="退款金额" prop="refund_fee">
                <el-input-number v-model="form.refund_fee"></el-input-number>
        	</el-form-item>
            <el-form-item label="退款积分" prop="refund_score">
                <el-input-number v-model="form.refund_score"></el-input-number>
        	</el-form-item>
            <el-form-item label="退款贝壳" prop="refund_shell">
                <el-input-number v-model="form.refund_shell"></el-input-number>
        	</el-form-item>
            <el-form-item label="添加时间" prop="createtime">
                <el-date-picker v-model="form.createtime" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="更新时间" prop="updatetime">
                <el-date-picker v-model="form.updatetime" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="删除时间" prop="deletetime">
                <el-date-picker v-model="form.deletetime" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="店铺id" prop="store_id">
                <el-input-number v-model="form.store_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="买家退快递公司" prop="express_name">
                <el-input v-model="form.express_name" clearable></el-input>
        	</el-form-item>
            <el-form-item label="买家退快递公司编号" prop="express_code">
                <el-input v-model="form.express_code" clearable></el-input>
        	</el-form-item>
            <el-form-item label="买家退快递单号" prop="express_no">
                <el-input v-model="form.express_no" clearable></el-input>
        	</el-form-item>
            <el-form-item label="店铺发快递公司" prop="store_express_name">
                <el-input v-model="form.store_express_name" clearable></el-input>
        	</el-form-item>
            <el-form-item label="店铺发快递公司编号" prop="store_express_code">
                <el-input v-model="form.store_express_code" clearable></el-input>
        	</el-form-item>
            <el-form-item label="店铺发快递单号" prop="store_express_no">
                <el-input v-model="form.store_express_no" clearable></el-input>
        	</el-form-item>
            <el-form-item label="联系电话" prop="store_phone">
                <el-input v-model="form.store_phone" clearable></el-input>
        	</el-form-item>
            <el-form-item label="收货人" prop="consignee">
                <el-input v-model="form.consignee" clearable></el-input>
        	</el-form-item>
            <el-form-item label="详细地址" prop="address">
                <el-input v-model="form.address" clearable></el-input>
        	</el-form-item>
            <el-form-item label="平台状态" prop="sys_status">
                <el-switch v-model="form.sys_status" :active-value="1" :inactive-value="0"></el-switch>
        	</el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="visible=false" >取 消</el-button>
            <el-button v-if="mode!='read'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
        </template>
    </el-dialog>
</template>

<script>
    
    export default {
        emits: ['success', 'closed'],
        
        data() {
            return {
                mode: "create",
                titleMap: {
                    read: '查看',
                    create: '新增',
                    update: '编辑',
                },
                visible: false,
                isSaveing: false,
                form: {
                    id: 0,
					aftersale_sn: '',
					user_id: '',
					type: '',
					type_str: '',
					phone: '',
					activity_id: '',
					activity_type: '',
					order_id: '',
					order_item_id: '',
					goods_id: '',
					goods_sku_price_id: '',
					goods_sku_text: '',
					goods_title: '',
					goods_image: '',
					goods_original_price: '',
					discount_fee: '',
					goods_price: '',
					goods_num: '',
					dispatch_status: '',
					dispatch_fee: '',
					aftersale_status: '',
					refund_status: '',
					ps: '',
					memo: '',
					images: '',
					refund_fee: '',
					refund_score: '',
					refund_shell: '',
					createtime: '',
					updatetime: '',
					deletetime: '',
					store_id: '',
					express_name: '',
					express_code: '',
					express_no: '',
					store_express_name: '',
					store_express_code: '',
					store_express_no: '',
					store_phone: '',
					consignee: '',
					address: '',
					sys_status: '',
                },
                rules: {
                },
				type_option:{"refund":"退款","return":"退货","change":"换货","other":"其他"},
				activity_type_option:{"0":"关闭","1":"开启"},
				dispatch_status_option:{"0":"未发货","1":"已发货","2":"已收货"},
				aftersale_status_option:{"-1":"拒绝","0":"未处理","1":"处理中","2":"售后完成"},
				refund_status_option:{"-1":"拒绝退款","0":"未退款","1":"同意"},
				sys_status_option:{"0":"未介入","1":"申请介入","2":"处理中","3":"完成"},
            }
        },
        methods: {
            open(mode='create'){
                this.mode = mode;
                this.visible = true;
                return this
            },
            submit(){
                this.$refs.dialogForm.validate(async (valid) => {
                    if (valid) {
                        this.isSaveing = true;
                        var res = await this.$API.order_aftersale[this.mode].post(this.form);
                        this.isSaveing = false;
                        if(res.code == 200){
                            this.$emit('success', this.form, this.mode)
                            this.visible = false;
                            this.$message.success(res.message)
                        }else{
                            this.$alert(res.message, "提示", {type: 'error'})
                        }
                    }else{
                        return false;
                    }
                })
            },
            setData(data){
                this.$TABLE.assign(this,data);
            }
        }
    }
</script>